package interview.huawei.myself.machine_test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int c = in.nextInt();
        int b = in.nextInt();
        int[] nums = new int[10];
        for (int i = 0; i < 10; i++) {
            nums[i] = in.nextInt();
        }

        HashMap<Integer, Integer> m = new HashMap<>();
        for (int n : nums) {
            ArrayList<Integer> bits = new ArrayList<>();

            while (n > 0) {
                bits.add(n % 16);
                n /= 16;
            }
            for (int i = bits.size(); i < 16; i++) {
                bits.add(0);
            }
            int sum = 0;
            for (int i = 15; i > 0; i -= 2) {
                sum += bits.get(i) * 16;
                sum += bits.get(i - 1);
            }
            int r = sum % b;
            if (r < c) {
                if (m.get(r) == null) {
                    m.put(r, 1);
                } else {
                    m.put(r, m.get(r) + 1);
                }
            }
        }

        int max = -1;
        for (Map.Entry<Integer, Integer> n : m.entrySet()) {
            if(n.getValue() > max)
                max = n.getValue();
        }
        System.out.println(max);
    }
}